<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
* 前台首页控制器
* 主要获取首页聚合数据
*/
class SearchController extends HomeController {

//系统首页
public function index(){
 //模糊搜索   
$list = D('Document')->page(45);
$this->assign('page',$list['data1']);
$this->assign('data',$list['data2']);
//選項卡
$this->tab();
$this->hots();
$this->logo();
$this->display("Search/search");
}
public function detail(){
 $this->logo();     
$id = $_GET['id'];
if(isset($id))
{
$list = D('Document')->detail($id);
$photo = explode(',', $list['pic']);
$photo2 = explode(',', $list['wpic']);
$photo3 = explode(',', $list['npic']);
$map = explode(',', $list['mapsite']);
$this->assign('map',$map);
$this->assign('photo',$photo);
$this->assign('photo2',$photo2);
$this->assign('photo3',$photo3);
$this->assign('data',$list);
$this->display("Search/detail");

}

}
//模糊搜索
public function likesearch(){
//選顯卡
$this->tab();
$this->hots();
$this->addhot();
 $this->logo(); 
$title = $_POST['title'];
if(isset($title))
{
 //模糊搜索
$list = D('Document')->likesearch($title,45);
 
$this->assign('page',$list['data1']);
$this->assign('data',$list['data2']);
$this->assign('empty','<p class="empty">沒有找到相關的樓盤</p>');


$this->display("Search/search");
}

}
//選顯卡搜索
public function tabsearch(){
    //選項卡
    $this->tab();
     $this->logo(); 
    $sell = $_POST['selltype'];
    $price =  explode('-', $_POST['prices']);
    $housetype = $_POST['house_type'];
    $add = $_POST['adds'];
    $data = D('Document')->tabsearch($add,$housetype,$sell,$price[0],$price[1]);
   $this->assign('data',$data);
   $this->assign('empty','<p  class="empty">沒有找到相關的樓盤</p>');
   $this->display('Search/search');

}
//選顯卡
public function tab(){
    
    $list2 = D('Document')->lists(44);
foreach($list2 as $val)
{    
$search = explode(',', $val['search_add']);
$search2 = explode(',', $val['search_type']);
$search3 = explode(',', $val['search_prices']);

foreach($search3 as $key2)
{
    $search4[] = explode('-',$key2);
   }
}
$this->assign('search',$search);
$this->assign('search2',$search2);
$this->assign('search3',$search4);
}
//熱門搜索搜索量
public function addhot(){
    $title = $_POST['title'];
    $hot =  M('hots');
    $res =  $hot->where(array('title'=>$title))->select();
    if($res)
    {
      $hot ->where(array('title'=>$title))->setInc('num',1); 
    }
    else
    {
        $hot->add(array('title'=>$title,'num'=>1));
    }     
}
/**
 * 熱門搜索
 */
public function hots(){
       
   $list = M('hots')->order('num desc')->limit(4)->select();
   $this->assign('hots',$list);
}
public function logo(){
       $list2 = D('Document')->detail(35);
       $this->assign('logo',$list2);
}
}